#include <iostream>
#include <stdlib.h>
#define TestNumber 100
using namespace std;

int sort(int *arr, int n);
int format(int *arr, int n);

int main(int argc, char**argv)
{
    if (argc < 2)
    {
        cout << "please input something." << endl;
        return 0;
    }

    int arr[TestNumber + 2];

    for (int i = 0; i < TestNumber; i++)
    {
        arr[i + 2] = atoi(argv[i + 1]);
    }

    sort(arr, TestNumber);
    format(arr, TestNumber);
    return 1;
}

int format(int *arr, int n)
{
    cout << arr[0] << "/";
    cout << arr[1];
    cout << "/";
    for (int i = 0; i < TestNumber; i++)
    {
        cout << arr[i + 2] << "\t";
        if ((i + 1) % 6 == 0)
        {
            cout << "n";
        }
    }
    cout << endl;
    return 1;

}

int sort(int *arr, int n)
{

    int right = 0, left = 0, k, mid = 0;
    int temp;
    int compareCount = 0;
    int moveCount = 0;

    for (int i = 1; i < n; i++)
    {
        temp = arr[i + 2];
        left = 0;
        right = i - 1;
        moveCount += 3;
        while (left <= right)
        {
            mid = (left + right) / 2;
            if (temp < arr[mid + 2])
            {
                right = mid - 1;
                moveCount++;
            }
            else
            {
                left = mid + 1;
                moveCount++;
            }
            moveCount++;
            compareCount++;
        }
        for (int j = i - 1; j >= left; j--)
        {
            arr[j + 1 + 2] = arr[j + 2];
            moveCount++;
            compareCount++;
        }
        if (left != i)
        {
            arr[left + 2] = temp;
            moveCount++;
            compareCount++;
        }
        compareCount++;
    }

    arr[0] = moveCount;
    arr[1] = compareCount;
    // 将排序记录复制到原来的顺序表里
    //    for (k = 0; k < n; k++)
    //    {
    //        arr[k + 2] = temp[(first + k) % n];
    //    }
}



